// https://leetcode-cn.com/problems/longest-consecutive-sequence/



/**
 * @param {number[]} nums
 * @return {number}
 */
var longestConsecutive = function (nums) {
  if (nums.length < 2) {
    return nums.length;
  }
  // nums = [...new Set(nums)];
  nums.sort((a, b) => a - b);
  let length = 1, res = 0;
  nums.map((i, index) => {
    if (nums[index + 1] - i === 1) {
      length++;
    } else if (nums[index + 1] - i === 0) {

    } else {
      res = Math.max(length, res);
      length = 1;
    }
  });
  return res;
};


// const arry = [0, 3, 7, 2, 5, 8, 4, 6, 0, 1];
// const arry = [100, 4, 200, 1, 3, 2];
const arry = [4, 0, -4, -2, 2, 5, 2, 0, -8, -8, -8, -8, -1, 7, 4, 5, 5, -4, 6, 6, -3];
// const arry = [];
const res = longestConsecutive(arry);
console.log(res);